home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / shell / shell.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-07-06  |  11.2 KB  |  507 lines

  1. function spaceEvenly(arrMCs, nmTop, nmBottom, nmMaxMargin, blnHorizontally)
  2. {
  3.    blnHorizontally != null ? 0 : (blnHorizontally = 0);
  4.    ┬º┬ºpush("getEdge");
  5.    if(!blnHorizontally)
  6.    {
  7.    }
  8.    var ┬º┬ºpop() = ┬º┬ºpop();
  9.    ┬º┬ºpush("positionBeside");
  10.    if(!blnHorizontally)
  11.    {
  12.    }
  13.    var ┬º┬ºpop() = ┬º┬ºpop();
  14.    var nmTotalHeights = 0;
  15.    var len = arrMCs.length;
  16.    var a = 0;
  17.    while(a < len)
  18.    {
  19.       nmTotalHeights += !blnHorizontally ? arrMCs[a]._height : arrMCs[a]._width;
  20.       a++;
  21.    }
  22.    var nmMargin = (nmBottom - nmTop - nmTotalHeights) / (len - 1);
  23.    if(nmMaxMargin != null && nmMargin > nmMaxMargin)
  24.    {
  25.       nmMargin = nmMaxMargin;
  26.    }
  27.    !blnHorizontally ? (arrMCs[0]._y = nmTop) : (arrMCs[0]._x = nmTop);
  28.    var a = 1;
  29.    while(a < len)
  30.    {
  31.       positionBeside(arrMCs[a],arrMCs[a - 1],nmMargin);
  32.       a++;
  33.    }
  34. }
  35. function spaceVertically(arrMCs, nmTop, nmBottom, nmMaxMargin)
  36. {
  37.    var nmTotalHeights = 0;
  38.    var len = arrMCs.length;
  39.    var a = 0;
  40.    while(a < len)
  41.    {
  42.       nmTotalHeights += arrMCs[a]._height;
  43.       a++;
  44.    }
  45.    var nmMargin = (nmBottom - nmTop - nmTotalHeights) / (len - 1);
  46.    if(nmMaxMargin != null && nmMargin > nmMaxMargin)
  47.    {
  48.       nmMargin = nmMaxMargin;
  49.    }
  50.    arrMCs[0]._y = nmTop;
  51.    var a = 1;
  52.    while(a < len)
  53.    {
  54.       arrMCs[a].positionUnder(arrMCs[a - 1],nmMargin);
  55.       a++;
  56.    }
  57. }
  58. function SectionsList(xmlNode)
  59. {
  60.    var len = xmlNode.childNodes.length;
  61.    var nd;
  62.    var S;
  63.    var n = 0;
  64.    while(n < len)
  65.    {
  66.       nd = xmlNode.childNodes[n];
  67.       S = this[nd.attributes.id] = {};
  68.       for(var a in nd.attributes)
  69.       {
  70.          S[a] = nd.attributes[a];
  71.       }
  72.       if(nd.hasChildNodes())
  73.       {
  74.          S.label = nd.getText();
  75.       }
  76.       S.index = n;
  77.       n++;
  78.    }
  79.    this.length = xmlNode.childNodes.length;
  80.    ASSetPropFlags(this,"length",1);
  81.    return this;
  82. }
  83. function ColorsObject(node)
  84. {
  85.    var makeDictionaryObject = function(node)
  86.    {
  87.       var len = node.childNodes.length;
  88.       var objDict = {};
  89.       var nd;
  90.       var n = 0;
  91.       while(n < len)
  92.       {
  93.          nd = node.childNodes[n];
  94.          objDict[nd.attributes.id] = nd.attributes.value;
  95.          n++;
  96.       }
  97.       return objDict;
  98.    };
  99.    this.__data = makeDictionaryObject(node);
  100.    return this;
  101. }
  102. _global.resolvePath = function(path)
  103. {
  104.    if(path.indexOf("../") == -1)
  105.    {
  106.       return path;
  107.    }
  108.    var arr = path.split("/");
  109.    var i = 1;
  110.    while(i < arr.length)
  111.    {
  112.       var p = arr.indexOf("..",i);
  113.       if(p > 0)
  114.       {
  115.          if(arr[p - 1] != "..")
  116.          {
  117.             arr.splice(p - 1,2);
  118.          }
  119.          else
  120.          {
  121.             i++;
  122.          }
  123.       }
  124.       else
  125.       {
  126.          i = arr.length;
  127.       }
  128.    }
  129.    return arr.join("/");
  130. };
  131. MovieClip.prototype.__olm = MovieClip.prototype.loadMovie;
  132. MovieClip.prototype.loadMovie = function(strURL, strMethod)
  133. {
  134.    strURL = resolvePath(strURL);
  135.    this.__olm(strURL,strMethod);
  136. };
  137. Sound.prototype.__ols = Sound.prototype.loadSound;
  138. Sound.prototype.loadSound = function(strURL, blnStreaming)
  139. {
  140.    strURL = resolvePath(strURL);
  141.    this.__ols(strURL,blnStreaming);
  142. };
  143. XML.prototype.__ol = XML.prototype.load;
  144. XML.prototype.load = function(strURL)
  145. {
  146.    strURL = resolvePath(strURL);
  147.    this.__ol(strURL);
  148. };
  149. TextField.prototype.replaceText = function(str)
  150. {
  151.    Selection.setFocus(this);
  152.    Selection.setSelection(0,0);
  153.    this.replaceSel(str);
  154.    Selection.setSelection(str.length,this.length);
  155.    this.replaceSel(" ");
  156.    Selection.setFocus(null);
  157. };
  158. TextField.prototype.resize = function()
  159. {
  160.    this.autoSize = true;
  161.    var h = this.textHeight + 10;
  162.    this.autoSize = false;
  163.    this._height = h;
  164. };
  165. MovieClip.prototype.getBottom = function()
  166. {
  167.    return parseInt(this._y + this._height);
  168. };
  169. Button.prototype.getBottom = TextField.prototype.getBottom = MovieClip.prototype.getBottom;
  170. MovieClip.prototype.positionUnder = function(objUnder, margin)
  171. {
  172.    if(margin == null)
  173.    {
  174.       margin = 0;
  175.    }
  176.    this._y = objUnder.getBottom() + margin;
  177. };
  178. Button.prototype.positionUnder = TextField.prototype.positionUnder = MovieClip.prototype.positionUnder;
  179. Object.prototype.dump = function()
  180. {
  181.    var strOut = "--- Start object dump ---\n";
  182.    for(var i in this)
  183.    {
  184.       strOut += i + " : " + this[i] + "\n";
  185.    }
  186.    strOut += "--- End object dump ---";
  187.    trace(strOut);
  188. };
  189. Array.prototype.indexOf = function(val, from)
  190. {
  191.    var len = this.length;
  192.    if(from == null)
  193.    {
  194.       from = 0;
  195.    }
  196.    var i = from;
  197.    while(i < len)
  198.    {
  199.       if(this[i] == val)
  200.       {
  201.          return i;
  202.       }
  203.       i++;
  204.    }
  205.    return -1;
  206. };
  207. Array.prototype.lastIndexOf = function(val, from)
  208. {
  209.    var len = this.length;
  210.    if(from == null)
  211.    {
  212.       from = len;
  213.    }
  214.    var i = from;
  215.    while(i >= 0)
  216.    {
  217.       if(this[i] == val)
  218.       {
  219.          return i;
  220.       }
  221.       i--;
  222.    }
  223.    return -1;
  224. };
  225. String.prototype.replace = function(srch, repl)
  226. {
  227.    return this.split(srch).join(repl);
  228. };
  229. MovieClip.prototype.pause = function(nm)
  230. {
  231.    clearInterval(this.nmPauseID);
  232.    this.stop();
  233.    this.nmPauseID = setInterval(this,"unpause",nm);
  234.    this.onUnload = function()
  235.    {
  236.       clearInterval(this.nmPauseID);
  237.    };
  238. };
  239. MovieClip.prototype.unpause = function()
  240. {
  241.    clearInterval(this.nmPauseID);
  242.    this.play();
  243. };
  244. MovieClip.prototype.disableButtons = function()
  245. {
  246.    for(var o in this)
  247.    {
  248.       if(this[o].__proto__ == Button.prototype)
  249.       {
  250.          this[o].enabled = false;
  251.       }
  252.    }
  253. };
  254. MovieClip.prototype.enableButtons = function()
  255. {
  256.    for(var o in this)
  257.    {
  258.       if(this[o].__proto__ == Button.prototype)
  259.       {
  260.          this[o].enabled = true;
  261.       }
  262.    }
  263. };
  264. MovieClip.prototype.removeAllMovieClips = function()
  265. {
  266.    for(var m in this)
  267.    {
  268.       if(typeof this[m] == "movieclip")
  269.       {
  270.          this[m].removeAllMovieClips();
  271.          this[m].removeMovieClip();
  272.       }
  273.    }
  274. };
  275. Color.prototype.reset = function()
  276. {
  277.    var objReset = {ab:0,aa:100,bb:0,ba:100,gb:0,ga:100,rb:0,ra:100};
  278.    this.setTransform(objReset);
  279. };
  280. ASSetPropFlags(Object.prototype,"dump",1);
  281. ASSetPropFlags(MovieClip.prototype,"getBottom,positionUnder,pause,unpause,disableButtons,enableButtons,removeAllMovieClips,__olm",1);
  282. ASSetPropFlags(TextField.prototype,"getBottom,positionUnder,resize",1);
  283. ASSetPropFlags(Button.prototype,"getBottom,positionUnder",1);
  284. ASSetPropFlags(Array.prototype,"indexOf,lastIndexOf",1);
  285. ASSetPropFlags(Sound.prototype,"__ols",1);
  286. ASSetPropFlags(XML.prototype,"__ol",1);
  287. MovieClip.prototype.addOnLoadHandler = function(path, func)
  288. {
  289.    if(MovieClip._onLoadHandler_ == undefined)
  290.    {
  291.       MovieClip._onLoadHandler_ = {};
  292.    }
  293.    if(func == null)
  294.    {
  295.       delete MovieClip._onLoadHandler_[path];
  296.    }
  297.    else
  298.    {
  299.       MovieClip._onLoadHandler_[path] = func;
  300.    }
  301. };
  302. ASSetPropFlags(MovieClip,["addOnLoadHandler"],1);
  303. sol = function(func)
  304. {
  305.    addOnLoadHandler(this,func);
  306. };
  307. gol = function()
  308. {
  309.    return MovieClip._onLoadHandler_[this];
  310. };
  311. MovieClip.prototype.addProperty("onLoad",gol,sol);
  312. MovieClip.prototype.addOnReadyHandler = function(path, func)
  313. {
  314.    if(MovieClip._onReadyHandler_ == undefined)
  315.    {
  316.       MovieClip._onReadyHandler_ = {};
  317.    }
  318.    if(func == null)
  319.    {
  320.       delete MovieClip._onReadyHandler_[path];
  321.    }
  322.    else
  323.    {
  324.       MovieClip._onReadyHandler_[path] = func;
  325.    }
  326. };
  327. ASSetPropFlags(MovieClip,["addOnReadyHandler"],1);
  328. sor = function(func)
  329. {
  330.    addOnReadyHandler(this,func);
  331. };
  332. gor = function()
  333. {
  334.    return MovieClip._onReadyHandler_[this];
  335. };
  336. MovieClip.prototype.addProperty("onReady",gor,sor);
  337. XML.prototype.ignoreWhite = true;
  338. XMLnode.prototype.byID = function(id)
  339. {
  340.    var len = this.childNodes.length;
  341.    var e = 0;
  342.    while(e < len)
  343.    {
  344.       var el = this.childNodes[e];
  345.       if(el.attributes.id == id)
  346.       {
  347.          return el;
  348.       }
  349.       e++;
  350.    }
  351.    return null;
  352. };
  353. XMLnode.prototype.byName = function(name)
  354. {
  355.    var len = this.childNodes.length;
  356.    var e = 0;
  357.    while(e < len)
  358.    {
  359.       var el = this.childNodes[e];
  360.       if(el.nodeName == name)
  361.       {
  362.          return el;
  363.       }
  364.       e++;
  365.    }
  366.    return null;
  367. };
  368. XMLnode.prototype.byIndex = function(index)
  369. {
  370.    if(this.childNodes[index])
  371.    {
  372.       return this.childNodes[index];
  373.    }
  374.    return null;
  375. };
  376. XMLnode.prototype.getText = function()
  377. {
  378.    return this.firstChild.nodeValue;
  379. };
  380. XMLnode.prototype.byPath = function(path)
  381. {
  382.    var tmp = this;
  383.    var arrPath = path.split("/");
  384.    var len = arrPath.length;
  385.    var n = 0;
  386.    while(n < len)
  387.    {
  388.       var str = arrPath[n];
  389.       if(str.charAt(0) == "@")
  390.       {
  391.          tmp = tmp.byID(str.substring(1));
  392.       }
  393.       else if(str.charAt(0) == "#")
  394.       {
  395.          tmp = tmp.byIndex(parseInt(str.substring(1)));
  396.       }
  397.       else
  398.       {
  399.          tmp = tmp.byName(str);
  400.       }
  401.       if(!tmp)
  402.       {
  403.          return undefined;
  404.       }
  405.       n++;
  406.    }
  407.    return tmp;
  408. };
  409. ASSetPropFlags(XML.prototype,"byID,byName,byIndex,byPath,getText",1);
  410. SectionsList.prototype.indexOf = function(str)
  411. {
  412.    var i = this.length - 1;
  413.    for(var o in this)
  414.    {
  415.       if(this[o].id == str)
  416.       {
  417.          return i;
  418.       }
  419.       i--;
  420.    }
  421.    return -1;
  422. };
  423. SectionsList.prototype.item = function(nm)
  424. {
  425.    var i = this.length - 1;
  426.    for(var o in this)
  427.    {
  428.       if(i == nm)
  429.       {
  430.          return this[o];
  431.       }
  432.       i--;
  433.    }
  434.    return null;
  435. };
  436. ASSetPropFlags(SectionsList.prototype,"item,indexOf",1);
  437. ColorsObject.prototype.__getString = function(str)
  438. {
  439.    var val = this.__data[str];
  440.    if(val == null)
  441.    {
  442.       if(str.charAt(0) != "#" || str.length != 7)
  443.       {
  444.          error("ColorsObject : color \'" + str + "\' not recognised");
  445.          return null;
  446.       }
  447.       val = str.substring(1);
  448.    }
  449.    return val;
  450. };
  451. ColorsObject.prototype.getString = function(str)
  452. {
  453.    return "#" + this.__getString(str);
  454. };
  455. ColorsObject.prototype.getHex = function(str)
  456. {
  457.    return parseInt("0x" + this.__getString(str));
  458. };
  459. _global.fade = function(soundToFade, volumeToSet)
  460. {
  461.    onEnterFrame = function()
  462.    {
  463.       if(soundToFade.getVolume() > volumeToSet)
  464.       {
  465.          soundToFade.setVolume(soundToFade.getVolume() - 5);
  466.       }
  467.       else if(soundToFade.getVolume() < volumeToSet)
  468.       {
  469.          soundToFade.setVolume(soundToFade.getVolume() + 1);
  470.       }
  471.       if(soundToFade.getVolume() <= 0)
  472.       {
  473.          soundToFade.stop();
  474.          delete soundToFade;
  475.          delete this.onEnterFrame;
  476.       }
  477.       else if(soundToFade.getVolume() == volumeToSet)
  478.       {
  479.          delete this.onEnterFrame;
  480.       }
  481.    };
  482. };
  483. if(PLAY_MODE == undefined)
  484. {
  485.    PLAY_MODE = CustomActions == null ? "director" : "authoring";
  486. }
  487. if(PLAY_MODE == "director")
  488. {
  489.    _global.lingo = function(str)
  490.    {
  491.       getURL("lingo:" + str,"");
  492.    };
  493. }
  494. else if(PLAY_MODE == "browser")
  495. {
  496.    _global.lingo = function(str)
  497.    {
  498.    };
  499.    _global.statusBar = function(str)
  500.    {
  501.       getURL("javascript:void(window.status=\'" + str + "\')","");
  502.    };
  503. }
  504. ISSUE_XMLFILE = "../../assets/xml/issue.xml";
  505. PROMOS_XMLFILE = "xml/promos.xml";
  506. _global.Tardis = this;
  507.